<?php
namespace app\index\controller;
use app\model\User;
use think\console\command\make\Controller;
use think\Request;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        
    	$requsest = Request::instance();
    	echo $requsest->domain();
    	echo $requsest->method();
    	var_dump($requsest->param());
    }

    public function db(){
    	$result = Db::query('SELECT * FROM `think_data`');
		var_dump($result);
		echo '哈哈哈123';
	}
	public function sign(){
		
		header('Access-Control-Allow-Origin:*');
		header('Access-Control-Allow-Methods:POST,GET,OPTIONS');
		header('Access-Control-Allow-Headers:x-requested-with,content-type,requesttype,token');
		$request = @file_get_contents('php://input'); 
		$request = json_decode($request,TRUE);
		$user = new User;
		// post数组中只有name和email字段会写入
		$insert = $user->allowField(['id','name','email','birthday'])->save($request);
		echo $insert;
		
	}
	public function login(){
		// $request = User::select();
		// $res = $request[0]->name;
		header('Access-Control-Allow-Origin:*');
		header('Access-Control-Allow-Methods:POST,GET,OPTIONS');
		header('Access-Control-Allow-Headers:x-requested-with,content-type,requesttype,token');
		$request = @file_get_contents('php://input'); 
		$request = json_decode($request,TRUE);
		$name = $request['name'];
		$birthday = $request['birthday'];

		$user = new User();
		$user = User::where('name', $name)->find();
		if($user == null){
			echo "用户不存在";
		}else{
			if($user->birthday == $birthday){
				echo "密码正确";
			}else{
				echo "密码错误";
			};
		}
		

		
	}
	
	public function add(){
		$user = new User();
		$insert = $user -> save([
			 'id'  => '3',
			 'name'  => 'wangwu',
			 'email'  => '13155554@163.com',
			 'birthday'  => '2000',
		 ]);
		 echo $insert;
	}


}
// $result = Db::execute('SELECT * FROM `think_data`');
// insert into think_data (name,status) values("张三","233")